package com.anysoft.formula;

/**
 * 过滤器框架
 *
 * @since 1.6.12.57 [20200103]
 */
public class Filter extends Function {
    public Filter() {
        super("filter");
    }

    public void checkArgument(Expression arg) throws FormulaException {
        if (getArgumentCount() > 2){
            throw new FormulaException("filter function only supports 2 arguments.");
        }
    }

    public ExprValue getValue(DataProvider provider) throws FormulaException {
        if (getArgumentCount() != 2){
            throw new FormulaException("filter function need at least 1 argument.we have " + getArgumentCount());
        }
        String data = getArgument(0).getValue(provider).getString();
        String pattern = getArgument(1).getValue(provider).getString();
        return new ExprValue(doFilter(data,pattern,provider));
    }

    protected String doFilter(String data, String pattern, DataProvider provider){
        return data;
    }
}